const { Client, Intents, DiscordAPIError } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const ytdl = require("ytdl-core")
const fs = require('fs');
client.commands = new Discord.Collection(); //error here
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`)
client.commands.set(command.name, command);
}
const PREFIX = '$';
var version = '1.0.1'
var servers = {};
client.once('ready', () => {
console.log ('Smegma Music is online!');
});
client.on('message', message=>{
if(!message.content.startsWith(PREFIX) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args. shift().toLowerCase();
if(command === 'ping'){
message.channel.send('Shutup Bitch!');{
}
function play(connection, message){
var server = servers [message.guild.id];
server.dispatcher = connection.playStream(ytdl(server.queue[0], {filter: "audioonly"}));
server.queue.shift();
server.dispatcher.on("end", function(){
if(server.queue[0]){
play(connection, message);
}else {
connection.disconnect();
}
});
client.login('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); //at end
}
}});
Line 9 is where the problem is. "client.commands = new Discord.Collection();" I get an error when I try to run 'node .' saying
ReferenceError: Discord is not defined at Object. (C:\MusicBot\main.js:9:23)
It was working yesterday, however this was with a different approach to commands. I am trying to create a basic command handler here.
Above trying to make a new collection, you can define discord like this:
const Discord = require("discord.js")